<template>
  <div class="mod-prod-brand">
    <div class="search-bar">
      <el-form :inline="true" class="search-form" size="small">
        <div class="input-row">
          <el-form-item :label="$t('chatMsg.userName')" prop="userName">
            <el-input v-model="page.userName" :placeholder="$t('chatMsg.keyupUserName')" maxlength="30"  />
          </el-form-item>
          <el-form-item>
            <div class="default-btn primary-btn" @click="searchChange(true)">{{$t('crud.searchBtn')}}</div>
            <div class="default-btn" @click="resetSearchForm()">{{$t('product.reset')}}</div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="main-container">
      <div class="table-con spec-table">
        <el-table
          ref="specListTable"
          :data="dataValue"
          header-cell-class-name="table-header"
          row-class-name="table-row"
          style="width: 100%">

          <el-table-column
            prop="id"
            :label="$t('chatMsg.userId')"
            >
          </el-table-column>

          <el-table-column
            prop="userName"
            :label="$t('chatMsg.userName')"
           >
            <template slot-scope="scope">
              <div class="table-cell-text">{{ scope.row.userName }}</div>
            </template>
          </el-table-column>

          <el-table-column
            :label="$t('chatMsg.userImg')"
           >
            <template slot-scope="scope">
              <img style="width:100px;height: 100px;" :src="resourcesUrl+scope.row.userPortrait"  alt="">
            </template>
          </el-table-column>


          <el-table-column
            prop="createDate"
            :label="$t('chatMsg.createTime')"
            >
          </el-table-column>

          <el-table-column
            :label="$t('chatMsg.bannedStatus')"
            >
            <template slot-scope="scope">
              <div class="table-cell-text">{{ scope.row.status?$t('chatMsg.overBrand'):$t('chatMsg.noBrand') }}</div>
            </template>
          </el-table-column>

          <el-table-column
            :label="$t('chatMsg.onlineStatus')"
            >
            <template slot-scope="scope">
              <div class="table-cell-text">{{ scope.row.onlineStatus?$t('chatMsg.overonlineStatus'):$t('chatMsg.noonlineStatus') }}</div>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            :label="$t('publics.operating')"
            width="400"
            >
            <template slot-scope="scope">
              <div class="text-btn-con">
                <div
                  class="default-btn text-btn"
                  @click="lookUserFunc(scope.row.id)"
                  >{{$t('user.details')}}
                </div>
                <!--加入黑名单 -->
<!--                <div-->
<!--                  class="default-btn text-btn"-->
<!--                  @click="bannedFunc(scope.row)"-->
<!--                  > {{ $t('chatMsg.joinblacklist')}}-->
<!--                </div>-->

                <div
                  class="default-btn text-btn"
                  @click="refreshFunc(scope.row)"
                  >{{$t('chatMsg.refreshStatus')}}
                </div>
<!--                <div-->
<!--                  class="default-btn text-btn"-->
<!--                  @click="writeIffFunc(scope.row)"-->
<!--                  >{{$t('chatMsg.writeIff')}}-->
<!--                </div>-->

              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        v-if="dataValue.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
    <!-- 发布群公告 -->
    <groupAnnouncement ref="announceChild" :itemVal="itemVal"></groupAnnouncement>
  </div>
</template>

<script>
  import groupAnnouncement from './components/groupAnnouncement'

  export default {
    components: {groupAnnouncement},
    data () {
      return {
        resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
        dataValue: [],
        groupId: null,
        itemVal: {}, // 获取当前列数据
        // 修改
        page: {
          pageSize: 10,
          pageNum: 1,
          total: null,
          userName: ''
        }
      }
    },

    created () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList (page, newData = false) {
        this.$http({
          url: this.$http.adornUrl('/admin/melt/user/getUserList'),
          method: 'get',
          params: this.page
        }).then((data) => {
          this.dataValue = data.data.list
          this.page.total = data.data.total
          console.log('列表', data)
        })
      },

      // 搜索
      searchChange () {
        this.getDataList()
      },

      // 重置
      resetSearchForm () {
        this.page.userName = ''
        this.getDataList()
      },

      // 查看用户信息
      lookUserFunc (id) {
        this.$refs.announceChild.visible = true
        this.groupId = id
        this.$nextTick(() => {
          this.$refs.announceChild.getUserDetail(id)
        })
      },

      // 加入黑名单
      bannedFunc (row) {
        console.log('====', row)
        let obj = {
          userId: row.id,
          userBlacklist: [row.id]
        }
        this.$http({
          url: this.$http.adornUrl('/admin/melt/user/userBlacklistAdd'),
          method: 'post',
          data: obj
        }).then((data) => {
          console.log('状态', data)
          this.$message({
            message: this.$i18n.t('chatMsg.overjoinblacklist'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList()
            }
          })
        })
      },

      // 刷新用户信息状态
      refreshFunc (row) {
        console.log('1111', row)
        let dissolveValue = {
          id: row.id,
          name: row.userName,
          portrait: row.userPortrait
        }
        this.$http({
          url: this.$http.adornUrl('/admin/melt/user/refershUserInfo'),
          method: 'post',
          data: dissolveValue
        }).then((data) => {
          this.$message({
            message: this.$i18n.t('chatMsg.refreshStSuccess'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList()
            }
          })
        })
      },

      // 注销
      writeIffFunc (row) {
        console.log('1111', row)
        let dissolveValue = {
          userId: row.id
        }
        this.$http({
          url: this.$http.adornUrl('/admin/melt/user/abandon'),
          method: 'get',
          params: dissolveValue
        }).then((data) => {
          this.$message({
            message: this.$i18n.t('chatMsg.writeIffSuccess'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList()
            }
          })
        })
      },

      // 分页
      handleSizeChange (val) {
        this.page.pageSize = val
        this.getDataList()
      },
      handleCurrentChange (val) {
        this.page.pageNum = val
        this.getDataList()
      }

    }
  }
</script>
